package net.neptech.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.validation.Valid;
import net.neptech.feign.SystemFeignClient;
import net.neptech.service.AuthService;
import net.neptech.vm.ResponseResult;
import net.neptech.vo.LoginBo;
import net.neptech.vo.RegisterBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * @Author: liyuxiang
 * @Date: 2025/8/5 16:52
 */
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Autowired
    private AuthService authService;
    @Autowired
    SystemFeignClient systemFeignClient;

    /**
     * 登录
     */
    @PostMapping("/login")
    public ResponseResult<String> login(@Valid @RequestBody LoginBo loginBo) {
        String token = authService.login(loginBo.getUsername(), loginBo.getPassword());
        return ResponseResult.success(token);
    }

    @PostMapping("/register")
    public ResponseResult<Void> register(@Valid @RequestBody RegisterBo registerBo) {
        authService.register(registerBo.getUsername(), registerBo.getPassword(), registerBo.getTelphone());
        return ResponseResult.success();
    }

    @PostMapping("/logout")
    public ResponseResult<Void> logout() {
        authService.logout();
        return ResponseResult.success();
    }

    @GetMapping("/test")
    public ResponseResult<Set<String>> test() {
        return systemFeignClient.getUserPermissions();
    }

    @GetMapping("/test1")
    @SaCheckPermission("system:config:list")
    public ResponseResult<String> test1() {
        return ResponseResult.success("拦截");
    }

    /**
     * 微信登录/注册
     */
    @PostMapping("/wxLogin")
    public ResponseResult<String> wxLogin(@RequestBody String code) {
        String token = authService.wxLogin(code);
        return ResponseResult.success(token);
    }
}
